<template>
    <el-dialog v-model="flag" width="500">
        <el-form :model="form">
            <el-form-item label="姓名" v-if="type == 5">
                <el-input v-model="form.name" autocomplete="off" />
            </el-form-item>
            <el-form-item label="账号" v-if="type == 5">
                <el-input v-model="form.Account" autocomplete="off" />
            </el-form-item>
            <el-form-item label="公开作品数" v-if="type == 5">
                <el-input v-model="form.works" autocomplete="off" />
            </el-form-item>
            <el-form-item label="编辑作品书" v-if="type == 5">
                <el-input v-model="form.editor" autocomplete="off" />
            </el-form-item>
            <el-form-item label="点赞数" v-if="type == 5">
                <el-input v-model="form.like" autocomplete="off" />
            </el-form-item>
            <el-form-item label="评论数" v-if="type == 5">
                <el-input v-model="form.review" autocomplete="off" />
            </el-form-item>
            <el-form-item label="班级名称" v-if="type == 6">
                <el-input v-model="form.grade" autocomplete="off" />
            </el-form-item>
            <el-form-item label="姓名" v-if="type == 7">
                <el-input v-model="form.mingzi" autocomplete="off" />
            </el-form-item>
            <el-form-item label="账号" v-if="type == 7">
                <el-input v-model="form.zhanghaos" autocomplete="off" />
            </el-form-item>
            <el-form-item label="真实姓名" v-if="type == 7">
                <el-input v-model="form.namess" autocomplete="off" />
            </el-form-item>
            <el-form-item label="手机号" v-if="type == 7">
                <el-input v-model="form.phone" autocomplete="off" />
            </el-form-item>
            <el-form-item label="初始密码" v-if="type == 7">
                <el-input v-model="form.passwords" autocomplete="off" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="add">
                    添加
                </el-button>
            </div>
        </template>
    </el-dialog>
    <div>

    </div>
</template>

<script setup>
import { inject, reactive, ref, defineEmits } from "vue"
import { addstuses, addguan, addTeacher, banjidata } from "../api/index.ts"
import { userPiniaStore } from "@/stores"
const pinia = userPiniaStore()
const flag = inject("flag")
const forms = defineProps(["type"])
const chuan = defineEmits(["emitpasword"])
const emmit = async () => {
    const res = await banjidata()
    chuan("emitpasword", res.data.data)
}
const add = async () => {
    flag.value = false
    if (forms.type == 5) {
        const res = await addstuses({...form,
            id: new Date().getTime()
        })
        alert(res.data.msg)
        emmit()
    } else if (forms.type == 6) {
        const res = await addguan({
            ...form,
            id: new Date().getTime()
        })
        alert(res.data.msg)
        console.log(res.data.data)
        pinia.setbanjiId(res.data.data)

    } else if (forms.type == 7) {
        const res = await addTeacher({...form,
            id: new Date().getTime()
        })
        alert(res.data.msg)
        pinia.setAddTeacher(res.data.data)
    }


    form.name = ""
    form.Account = ""
    form.works = ""
    form.editor = ""
    form.like = ""
    form.review = ""
    form.grade = ""
    form.namess = ""
    form.zhanghaos = ""
    form.passwords = ""
    form.phone = ""
    form.mingzi = ""
}
const form = reactive({
    name: "",
    Account: "",
    works: "",
    editor: "",
    like: "",
    review: "",
    grade: "",
    namess: "",
    zhanghaos: "",
    passwords: "",
    phone: "",
    mingzi: "",
})
</script>

<style lang="scss" scoped></style>